package com.situ.crm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.crm.entity.User;
import com.situ.crm.service.IUserService;
import com.situ.crm.vo.ResultDataVO;

//用户控制器
@Controller
@RequestMapping(value = "/user")
public class UserController {

	@Autowired
	private IUserService userService;

	// 打开用户管理页面
	@GetMapping(value = "/index")
	public String openUserPage() {
		return "user";
	}

	// 分页查询用户列表
	@GetMapping(value = "/list")
	@ResponseBody
	public ResultDataVO selectUserList(String username, Integer page, Integer limit) {
		return userService.selectUserList(username, page, limit);
	}

	// 删除用户
	@PostMapping(value = "/del")
	@ResponseBody
	public void delUser(Integer id) {
		userService.delUser(id);
	}

	// 保存用户
	@PostMapping(value = "/save")
	@ResponseBody
	public void saveUser(User user) {
		userService.save(user);
	}

	// 根据ID查询用户的数据
	@GetMapping(value = "/{id}")
	@ResponseBody
	public User selectUserById(@PathVariable("id") Integer id) {
		return userService.selectUserById(id);
	}

	@PostMapping(value = "/changeRole")
	@ResponseBody
	public void changeRole(Integer userId, Integer roleId, String type) {
		userService.changeRole(userId, roleId, type);
	}

}
